<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3" xmlns:head="http://www.w3.org/1999/html">
<head th:include="/public/public_css::public_css ('库位管理')" />

<body style="background-color: #f2f2f2;">
<div class="layui-fluid larry-wrapper">
    <div class="layui-card">
        <div class="layui-row layui-col-space30">
        <div class="layui-col-xs24">
                <form class="layui-form layui-card-header  layui-card-header-auto" id="searchForm">
                    <div class="layui-inline">
                        <label class="layui-input-inline">库位名称</label>
                        <input type="text" class="layui-input" name="mc" id="mc" placeholder="请输入库位名称" />

                    </div>
                    <div class="layui-inline">
                        <label class="layui-input-inline">库区名称</label>
                        <input type="text" class="layui-input" name="kqmc" id="kqmc" placeholder="请输入库位名称" />
                    </div>
                    <div class="layui-inline">
                        <label class="layui-input-inline">库位属性</label>
                        <select name="sx">
                            <option value="">全部</option>
                            <option value="0">正常</option>
                            <option value="1">封存</option>
                            <option value="2">管控</option>
                            <option value="3">禁入</option>
                        </select>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-input-inline">库位类型</label>
                        <select name="lx">
                            <option value="">全部</option>
                            <option value="0">存储库位</option>
                            <option value="1">件拣货库位</option>
                            <option value="2">箱拣货库位</option>
                            <option value="3">箱/件拣货库位</option>
                            <option value="4">暂存库位</option>
                            <option value="5">集货库位</option>
                            <option value="6">组装工作库位</option>
                        </select>
                    </div>

                    <div class="layui-inline">
                        <label class="layui-input-inline">占用状态</label>
                        <select name="zyzt">
                            <option value="">全部</option>
                            <option value="0">未占用</option>
                            <option value="1">已占用</option>
                        </select>
                    </div>

                    <div class="layui-inline inline-search-btn">
                        <a class="layui-btn layui-btn-normal search_btn" lay-event="searchEvent" data-type="reload">查询</a>
                    </div>
                    <div class="layui-inline inline-reset-btn">
                        <button type="reset" class="layui-btn layui-btn-primary" style="background-color: #40AFFE">重置</button>
                    </div>
                </form>
            <!--顶部按钮展示区域 【 tpl-button 】 -->
            <div class="group-button tpl-button" id="toolbar"></div>
            <!--列表-->
            <section class="panel panel-padding layui-card-body">
                <div class="pro">
                    <table id="table" class="table text-nowrap"></table>
                </div>
            </section>
        </div>
    </div>
    </div>
</div>

</body>


<div th:include="/public/public_js::public_js"></div>
<div th:include="/public/public_btn::public_btn"></div>
<script th:inline="javascript">
    var functions = [[${functions}]];
    layui.use(['list', 'layer', 'zzpUtils', 'jquery', 'laydate', 'tablebutton'], function () {

        var zzpUtils= layui.zzpUtils,
            $ = layui.jquery,
            laydate = layui.laydate,
        tablebtn = layui.tablebutton;
        tablebtn.buildOnClick({
            type: 1,
            temp: $("#function_tpl"),
            functions: functions.headBtn,
            row: null,
            event: {
                searchEvent: function(){
                    zzpUtils.refreshTable("#table");
                },
                /*新增*/
                addEvent: function (data) {
                    add();
                },
                /*编辑*/
                editEvent: function (data) {
                    if (data.row != undefined) {
                        upDialog(data);
                    }
                },
                /*打印*/
                printEvent: function (data) {
                    if (data.row != undefined) {
                        printDialog(data);
                    }
                },
                /*删除*/
                deleteEvent: function (data) {
                    if (data.row != undefined) {
                        var ids = [];
                        ids.push(data.row.id)
                        delDialog(ids);
                    } else {
                        var arr = [];
                        var $rows = $table.bootstrapTable('getSelections');
                        if ($rows.length > 0) {
                            arr = $.map($rows, function (row) {
                                return row.id;
                            })
                            delDialog(arr);
                        }else{
                            layer.msg("至少选择一条数据");
                        }
                    }
                },
                /*多选删除*/
                multiDeleteEvent: function (data) {
                        multiDeleteDialog();
                },
                /*多选打印*/
                multiPrintEvent: function (data) {
                    multiPrintDialog();
                },
            }
        });
        //初始化
        zzpUtils.webSocket.init();
        //新增
        function add() {
            zzpUtils.dialog({
                title: "新增库位",
                type: 2,
                content: "/kuwei/addkuwei",
                area: ['80%', '90%'], //设置dialog大小，也可以不设置，
                end: function () {//增加成功后刷新
                    zzpUtils.refreshTable("#table");
                }
            });
        }
      //编辑库位
        function upDialog(data) {
            var id=data.row.id;
            var show_sshzid=data.row.show_sshzid;
            var show_zyzt=data.row.show_zyzt;
            if(show_sshzid==""){
                layer.msg("该库位未绑定货主不可进行编辑");
            }else if(show_zyzt=="已占用"){
                layer.msg("该库位已占用不可进行编辑");
            }else{
                zzpUtils.dialog({
                    title: "修改库位",
                    type: 2,
                    content: "/kuwei/editkuwei?id=" + id,
                    area: ['80%', '80%'], //设置dialog大小，也可以不设置，
                    end: function () {//修改成功后刷新
                        zzpUtils.refreshTable("#table");
                    }
                });
            }
        }

        //删除库位
        function delDialog(ids) {

            zzpUtils.confirm("您将删除选择的数据", function (index) {
                zzpUtils.action({
                    url: "/wmslibraryposition/delete",
                    data: JSON.stringify({ids: ids}),
                    success: function (data) {
                        setTimeout(function () {
                            layer.msg(data.title);
                        }, 500);
                        zzpUtils.refreshTable("#table");
                    }, error: function (xhr, textStatus) {
                        console.log(textStatus);
                        console.log(xhr)
                    }
                })
            })
            return false;
        }
        //打印
        function printDialog(data) {
            var mc=data.row.mc;
            zzpUtils.confirm("您将打印库位信息", function (index) {
                var LODOP = getLodop();
                LODOP.PRINT_INIT('打印库位信息');
                LODOP.ADD_PRINT_BARCODE(48, 34, 270, 47, "EAN128B", mc);
                LODOP.PREVIEW();
            })
        }
        //多选删除
        function multiDeleteDialog(){
            var $rows = $table.bootstrapTable('getSelections');
            if ($rows.length == 0) {
                layer.msg("请选择一条进行删除");
            } else {
                var ids = $.map($rows, function (row) {
                    return row.id;
                })
                zzpUtils.confirm("是否确定删除库位", function (index) {
                    zzpUtils.action({
                        url: "/wmslibraryposition/delete",
                        data: JSON.stringify({ids:ids}),
                        success: function (data) {
                            setTimeout(function () {
                                layer.msg(data.title+","+data.message);
                            }, 500);
                            zzpUtils.refreshTable("#table");
                        }, error: function (xhr, textStatus) {
                            console.log(textStatus);
                            console.log(xhr)
                        }
                    })
                })
                return false;

            }
        }
        //多选打印
        function multiPrintDialog(){
            var $rows = $table.bootstrapTable('getSelections');
            if ($rows.length > 0) {
                zzpUtils.confirm("您将打印库位信息", function (index) {
                    var LODOP=getLodop();
                    LODOP.PRINT_INIT('打印库位信息');
                    for(var i=0;i<$rows.length;i++){
                        LODOP.ADD_PRINT_BARCODE(48,34,270,47,"EAN128B",$rows[i].mc);
                        if(i>=0){
                            LODOP.NewPage();//分页
                        }
                    }
                    LODOP.PREVIEW();
                })
            } else {
                layer.msg("请选择一条进行打印");
            }
        }
        laydate.render({
            elem: '#test5'
            ,theme: '#20a0ff'
        })
        var $table = zzpUtils.table({
            elem: '#table',
            isApi: true,
            isOperate: true,
            pagination: true,
            url: '/wmslibraryposition/list',
            columns: [{
                field: '',
                checkbox: true
            }, {
                field: 'ckmc',
                title: '仓库名称'
            },{
                field: 'show_sshzid',
                title: '货主名称'
            },{
                field: 'kqmc',
                title: '库区名称'
            },{
                field: 'mc',
                title: '库位名称',
            },{
                field: 'show_sx',
                title: '库位属性'
            },{
                field: 'show_lx',
                title: '库位类型'
            },{
                field: 'show_hphf',
                title: '货品混放'
            },{
                field: 'show_pchf',
                title: '同批混放'
            },{
                field: 'cs',
                title: '层数'
            },{
                field: 'tps',
                title: '托盘数'
            },{
                field: 'show_zyzt',
                title: '占用状态'
            }],
            queryParams: function () {//查询条件
                return  zzpUtils.getFormJson($("#searchForm"));
            },
            detailFormatter: function (index, row) {
                return "这里就没有确定过11";
            },
            /*定义表格右侧按钮*/
            operateFormatter: operateFormatter

        });
        /*表格右侧按钮*/
        function operateFormatter(value, row, index) {
            var button = '<a class="tooltip2" id="tooltip' + row.id + '" data-tooltip-content="#tool' + row.id + '" id="btn_start"><i class="layui-icon layui-icon-more"></i></a>'
                + '<div class="tooltip_templates">'
                + '<span id="tool' + row.id + '">';
            for (var i = 0; i < functions.tableBtn.length; i++) {
                var btn = '<a class="layui-btn layui-btn-sm layui-btn-warm" lay-event="' + functions.tableBtn[i].event + '">'
                    + functions.tableBtn[i].name
                    + '</a>';
                    button += btn;
            }
            button += '</span>'
                + '</div>';
            return button;
        }
    });
</script>
</html>